package com.agann.util;

import com.agann.model.Memory;
import com.agann.model.Record;

public class MACD extends Memory {

	/**
	 * Type Code
	 */
	public static final String TYPE_CODE = "MACD";
	public static final String MACD_SCORE = "macd_score";
	public static final String SIGNAL_SCORE = "signal_score";
	public static final String MACD_HIST = "macd_hist";

	
	private int n1,n2,n3;
	private EMA_Util ema1,ema2,ema3;
	
	public MACD(String code) {
		super(code);
		//TODO Add Exception Check
		String[] args = code.split("@");
		n1 = Integer.valueOf(args[1]);
		n2 = Integer.valueOf(args[1]);
		n3 = Integer.valueOf(args[1]);
		ema1 = new EMA_Util(n1);
		ema2 = new EMA_Util(n2);
		ema3 = new EMA_Util(n3);
	}

	@Override
	public void update(Record record) {
		ema1.update(record.getClose());
		ema2.update(record.getClose());
		if ((ema1.getScore()!=0) && (ema2.getScore()!=0)) {
			setScore(MACD_SCORE, ema1.getScore()-ema2.getScore());
			ema3.update(ema1.getScore()-ema2.getScore());
			setScore(SIGNAL_SCORE, ema3.getScore());
			setScore(MACD_HIST, ema1.getScore()-ema2.getScore()-ema3.getScore());
		}		
	}

	@Override
	public void merge(String code) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void change(double rate) {
		// TODO Auto-generated method stub
		
	}
	
}
